package com.ruoyi.web.controller.erp;

import com.bonuo.erp.domain.SupplierProduct;
import com.bonuo.erp.service.SupplierProductService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "外购产品管理")
@RestController
@RequestMapping("/erp/supplierProduct")
public class SupplierProductController extends BaseController {
    @Autowired
    private SupplierProductService supplierProductService;

    /** 外购产品查询 */
    @ApiOperation(value = "外购产品查询",httpMethod = "GET")
    @GetMapping("/list")
    public TableDataInfo list(SupplierProduct supplierProduct, Integer pageNum, Integer pageSize) {
        if(pageNum != null && pageSize != null){
            startPage();
        }
        List<SupplierProduct> list = supplierProductService.selectSupplierProductList(supplierProduct);
        return getDataTable(list);
    }

    /** 添加 */
    @ApiOperation(value = "添加外购产品",httpMethod = "POST")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SupplierProduct supplierProduct) {
        return toAjax(supplierProductService.insertSupplierProduct(supplierProduct));
    }

    /** 修改 */
    @ApiOperation(value = "修改外购产品",httpMethod = "PUT")
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody SupplierProduct supplierProduct) {
        return toAjax(supplierProductService.updateSupplierProduct(supplierProduct));
    }

    /** 删除 */
    @ApiOperation(value = "删除外购产品",httpMethod = "DELETE")
    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable Integer id) {
        return toAjax(supplierProductService.deleteSupplierProductById(id));
    }

}
